package com.api.rocky.base;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.api.rocky.R;
import com.api.rocky.model.UserList;

public class GridUserAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<Map<String, Object>> mData;
      
      
    public GridUserAdapter(Context context,List<Map<String, Object>> mData){ 
        this.mInflater = LayoutInflater.from(context);
        this.mData = mData;
    } 
    public int getCount() { 
        return mData.size(); 
    } 

    public Object getItem(int arg0) { 
        return mData.get(arg0); 
    } 

    public long getItemId(int arg0) { 
        return arg0; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
          
    	UserList holder = null; 
        if (convertView == null) { 
              
            holder=new UserList();   
              
            convertView = mInflater.inflate(R.layout.gridview_user, null); 
            holder.face = (ImageView)convertView.findViewById(R.id.face); 
            holder.distance = (TextView)convertView.findViewById(R.id.distance);
            holder.sex = (ImageView)convertView.findViewById(R.id.sex); 
            convertView.setTag(holder); 
              
        }else { 
              
            holder = (UserList)convertView.getTag(); 
        } 
          
          
        holder.face.setBackgroundResource((Integer)mData.get(position).get("face")); 
        holder.distance.setText((String)mData.get(position).get("distance")); 
        holder.sex.setBackgroundResource((Integer)mData.get(position).get("sex")); 

        return convertView; 
    }
  
}
